package com.xinsoft.common;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @Author Li9527
 * @Description 全局状态码
 * @Date 2021/2/24 11:48
 **/
@Getter
@AllArgsConstructor
@SuppressWarnings({"", "AlibabaEnumConstantsMustHaveComment"})
public enum GlobalStatusEnum implements GlobalStatus {
    STATUS_SUCCESS("2000", "Success", "成功"),
    STATUS_ERROR("4000", "System Error", "系统错误"),

    STATUS_UNKNOWN_ERROR("000002", "Unknown Error", "未知异常"),
    STATUS_SERVER_UNAVAILABLE("000003", "Server Unavailable", "服务不可用"),

    //Jwt
    STATUS_JWT_REQUIRED("000010", "Jwt Token Required", "Token 不能为空！"),
    STATUS_JWT_EXPIRE("000011", "Jwt Expire", "Token 已过期！"),
    STATUS_JWT_OUT("000015", "Jwt out", "检测到有新终端登陆，您已被踢出！"),
    STATUS_JWT_SIGNATURE("000012", "Jwt Signature Verification Failed", "JWT签名认证失败"),
    STATUS_PASSWORD_VALID_FAILED("000013", "Password Verification Failed", "密码验证失败"),
    STATUS_JWT_UNKNOWN_ERROR("000014", "Jwt Unknown Error", "JWT未知异常"),

    //CRUD
    STATUS_SAVE_FAILED("000020", "Save Failed", "保存失败"),
    STATUS_CREATE_FAILED("000021", "Create Failed", "新增失败"),
    STATUS_UPDATE_FAILED("000022", "Update Failed", "更新失败"),
    STATUS_DELETE_FAILED("000023", "Delete Failed", "删除失败"),
    STATUS_QUERY_FAILED("000024", "Query Failed", "查询失败"),
    STATUS_API_INVALID("000025", "Invalid Api", "接口无效"),
    STATUS_PARAM_NULL("000026", "Param Required", "参数为空"),
    STATUS_PARAM_VALID_FAILED("000027", "Param Verification Failed", "参数验证失败"),
    STATUS_CHECK_FORM_FAILED("1000028", "Form Check Failed", "表单校验失败"),

    //Exception
    STATUS_YML_PROPERTIES_CONVERT_FAILED("000201", "Yml Failed To Convert Properties", "Yml转换Properties异常"),
    STATUS_PROPERTIES_YML_CONVERT_FAILED("000202", "Properties Failed To Convert Yml", "Properties转换Tml异常"),
    ENUM_MATCHING_EXCEPTION("000203", "Enum Matching Exception", "枚举匹配异常"),
    ITEM_NOT_FOUND_EXCEPTION("000204", "Item Not Found Exception", "未查到相关记录"),
    PASSWORD_MISTAKE_EXCEPTION("000205", "Password Mistake Exception", "密码错误"),
    USER_SYSTEM_MATCHING_EXCEPTION("000203", "User System Matching Exception", "用户系统匹配异常"),
    RUOYI_UNAUTHORIZED_EXCEPTION("000206", "Ruoyi Unauthorized Exception", "若依系统未验证失败"),
    RETRIEVE_SSO_USER_FAILED_EXCEPTION("000207", "Retrieve SSO user failed", "部门未授权"),
    DING_DEPT_UNAUTHORIZED_EXCEPTION("000208", "The Dept Of Ding Unauthorized Exception", "部门未授权"),
    DING_DEPT_DISABLE_EXCEPTION("000209", "The Dept Of Ding Disabled Exception", "部门被禁用"),
    FLOW_VERSION_EXCEPTION("000300", "Get Flow Main Version Failed", "获取流程版本失败");


    private String code;
    private String msg;
    private String desc;

    public static GlobalStatusEnum getByCode(String code) {
        return Arrays.asList(GlobalStatusEnum.values())
                .stream()
                .filter(oee -> oee.getCode().equals(code))
                .findFirst()
                .orElse(GlobalStatusEnum.STATUS_UNKNOWN_ERROR);

    }
}
